from  appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    def __init__(self):
        cap={
                "platformName": "Android",
                "appium:deviceName": "emulator-5554",
                "appium:automationName": "uiautomator2",
                "appium:appPackage": "cn.xuexi.android",
                "appium:appActivity": "com.xiachufang.activity.home.HomeActivity",
                "appium:noReset": True
        }
        #隐式等待
        self.driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",cap)
        self.driver.implicitly_wait(20)
    #定位元素
    def dingwei(self,loc):
        ele=self.driver.find_element(*loc)
        return ele
    #显示等待
    def xianshi(self,lco):
        ele=WebDriverWait(self.driver,2000).until(EC.element_to_be_clickable(loc))
        return  ele
    #截图
    def jietu(self,loc):
        self.driver.save_screenshot(loc)
    #滑动
    def huadong(self,a,b,c,d):
        self.driver.swipe(a,b,c,d)
    #轻敲
    def qingqiao(self,a,b):
        self.driver.swipe(a,b)
    #退出
    def tuichu(self):
        self.driver.quit()
    #系统按键
    def xitonganjian(self):
        self.driver.press_keycode(3)
    #查找元素
    def chazhao(self,loc):
        ele=self.driver.find_element(*loc)
        return  ele
